package com.wjc.business.controller.admin.web;


import com.wjc.business.BusinessApplication;
import com.wjc.server.dto.CommonDto;
import com.wjc.server.dto.CourseDto;
import com.wjc.server.dto.CoursePageDto;
import com.wjc.server.dto.PageDto;
import com.wjc.server.enums.CourseStatusEnum;
import com.wjc.server.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController("webCourseController")
@RequestMapping("/web/course")
public class CourseController {

    private static final Logger LOG= LoggerFactory.getLogger(BusinessApplication.class);
    public static final String BUSINESS_NAME = "课程";

    @Resource
    private CourseService courseService;

    /**
     * 列表查询，查询最新的3门已发布的课程
     */
    @GetMapping("/list-new")
    public CommonDto listNew() {
        PageDto pageDto = new PageDto();
        pageDto.setPage(1);
        pageDto.setSize(3);
        CommonDto responseDto = new CommonDto();
        List<CourseDto> courseDtoList = courseService.listNew(pageDto);
        responseDto.setContent(courseDtoList);
        return responseDto;
    }

    //列表查询
    @GetMapping("/list")
    public CommonDto list(@Valid CoursePageDto pageDto){
        pageDto.setStatus(CourseStatusEnum.PUBLISH.getCode());
        courseService.list(pageDto);
        CommonDto<CoursePageDto> pageDtoCommonDto = new CommonDto<>();
        pageDtoCommonDto.setContent(pageDto);
        return pageDtoCommonDto;
    }

    @GetMapping("/find/{id}")
    public CommonDto findCourse(@PathVariable Long id) {
        LOG.info("查找课程开始：{}", id);
        CommonDto responseDto = new CommonDto();
        CourseDto courseDto = courseService.findCourse(id);
        responseDto.setContent(courseDto);
        LOG.info("查找课程结束：{}", responseDto);
        return responseDto;
    }




}
